<template>
  <view>
    <Header></Header>
    <view class="card flex flex-col flex-center" v-if="!type">
      <view class="title">{{ title }}</view>
      <view class="describe" v-if="info.prev_comment">{{ info.prev_comment }}</view>
      <view class="score" v-if="info.paper_score !== ''">{{ info.paper_score }}分</view>
      <view class="describe" v-if="info.score_comment" v-html="info.score_comment"></view>
      <view class="btns">
        <view class="btn" @click="retest">重新评测</view>
        <view class="btn ml3 mr3" @click="moreEvaluating">更多评测</view>
        <view class="btn" @click="back">返回首页</view>
      </view>
    </view>
    <view class="card flex flex-col flex-center" v-else>
      <view class="title">{{ title }}</view>
      <view class="cell" style="line-height: 40rpx">
        <view class="fw">知识测评分析</view>
        <view v-for="(item, index) in info.zhishi" :key="index">{{ getText(item.zhishi) }}: {{ item.zhishiname }}</view>
        <view class="fw">思路测评分析</view>
        <view v-for="(item, index) in info.silu" :key="index">{{ getText(item.silu) }}: {{ item.siluname }}</view>
      </view>
      <view class="btns">
        <view class="btn ml3 mr3" @click="moreEvaluating">更多评测</view>
        <view class="btn" @click="back">返回首页</view>
      </view>
    </view>
  </view>
</template>
<script setup>
import { recResults } from '/api'
import { useStore } from 'vuex'

const { state, commit, dispatch } = useStore()
const student_id = ref()
const testpaper_id = ref()
const moduleclass_id = ref()
const type = ref()
const title = ref()
const info = ref({})

onLoad(async (options) => {
  moduleclass_id.value = options.moduleclass_id
  student_id.value = options.student_id
  testpaper_id.value = options.testpaper_id
  title.value = options.title
  type.value = options.type

  const params = {
    student_id: options.student_id
  }
  type.value == 1 ? (params.book_id = moduleclass_id.value) : type.value == 2 ? (params.moduleclass_id = moduleclass_id.value) : (params.testpaper_id = testpaper_id.value)
  const { data } = await recResults(params)
  info.value = data
})

function retest() {
  uni.navigateTo({
    url: `/pages/evaluating/evaluating?student_id=${student_id.value}&testpaper_id=${testpaper_id.value}`
  })
}

function moreEvaluating() {
  uni.reLaunch({
    url: `/pages/evaluating/index?student_id=${student_id.value}`
  })
}

function back() {
  dispatch('goHome')
}

function getText(type) {
  const list = ['良好', '有待提升', '薄弱']
  return list[Number(type) - 1]
}
</script>
<style lang="scss" scoped>
.card {
  .title {
    margin-top: 200rpx;
    font-weight: bold;
    font-size: 36rpx;
  }

  .score {
    margin-top: 200rpx;
    font-size: 70rpx;
    font-weight: 900;
  }

  .describe {
    margin-top: 100rpx;
    max-width: 1000rpx;
    font-weight: bold;
  }

  .btns {
    display: flex;
    margin-top: 100rpx;
    padding-bottom: 100rpx;

    .btn {
      width: 200rpx;
      height: 80rpx;
      border-radius: 10rpx;
      background-color: #377CB7;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}

.cell {
  width: 600rpx;
  margin-top: 200rpx;
}
</style>
